package com.cat.dynamicPlanning02;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/best-time-to-buy-and-sell-stock-with-transaction-fee/
 * @create 2025/10/17 21:52
 * @since JDK17
 */

public class Solution23 {
    public int maxProfit(int[] prices, int fee) {
        int n = prices.length, best = -prices[0];
        int[] dp = new int[n];
        for (int i = 1; i < n; i++) {   //
            dp[i] = Math.max(dp[i - 1], prices[i] - fee + best);
            best = Math.max(best, dp[i] - prices[i]);
        }

        return dp[n - 1];
    }
}
